<template>
	<view class="goods-item" >
		<!-- 左侧 -->
		<view class="goods-item-left" v-if="showRadio">
			<radio :checked="goods.goods_state" @click="RadioChangeHandler" color="#c00"></radio>
			<image :src="goods.goods_small_logo || defaultSrc" class="goods-pic" ></image>
		</view>
		<!-- 右侧 -->
		<view class="goods-item-right">
			<view class="goods-name">
				{{goods.goods_name}}
			</view>
			<view class="goods-info-box">
				<view class="goods-price">￥{{goods.goods_price | toFixed}}</view>
				<uni-number-box :value="goods.goods_count" :min="1" @change='numChange' ></uni-number-box>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-cart-goods",
		data() {
			return {
				defaultSrc:'http://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		props:{
			goods:{
				type : Object,
				default: null
			},
			showRadio:{
				type : Boolean,
				default : true
			}
		},
		filters:{
			toFixed(num){
				return Number(num).toFixed(2)
			}
		},
		methods:{
			RadioChangeHandler(){
				this.$emit('RadioChange',{
					goods_id : this.goods.goods_id,
					goods_state : !this.goods.goods_state,
					goods_count : this.goods.goods_count,
					goods_price : this.goods.goods_price
				})
			}, 
			numChange(val){
				
				this.$emit('NumChange',{
					goods_id : this.goods.goods_id,
					goods_count : +val
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.goods-item{
	width: 750rpx;
	box-sizing: border-box;
	display: flex;
	padding: 10px 5px;
	border-bottom: 1px solid #ededed;
	.goods-item-left{
		margin-right: 5px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.goods-pic{
			width: 100px;
			height: 100px;
			display: block;
		}
	}
	.goods-item-right{
		display: flex;
		flex : 1;
		flex-direction: column;
		justify-content: space-between;
		
		.goods-name{
			font-size: 14px;
		}
		.goods-info-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.goods-price{
				color: #c00;
				font-size: 16px;
			}
		}
		
	}
}
</style>